<!--#include file="config.inc.asp" -->
<% 
function LeftPad(stext,chrpad,ilength)
  dim sresult, sLength, i
  sResult = stext
  slength = len(stext)
  if slength < ilength then
    i = ilength - slength
	sResult = string(i,chrpad)
	sResult = sResult & sText
  end if
  LeftPad = sResult
end function

' Send CDO email message
function SendCDOEmail(remail, ccemail, bccemail, semail, ssubject, sbody)
  Dim Email
  Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
  Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 

  Const cdoAnonymous = 0 'Do not authenticate
  Const cdoBasic = 1 'basic (clear-text) authentication
  Const cdoNTLM = 2 'NTLM

  Set Email = Server.CreateObject("CDO.Message") 
  Email.Subject = ssubject 
  Email.Sender = semail 
  Email.From = semail 
  Email.To = remail
  if ccemail <> "" then
    Email.Cc = ccemail
  end if
  if bccemail <> "" then
    Email.Bcc = bccemail
  end if
  'Email.Bcc = "gdi@premier-oil.com"
  Email.HTMLBody = sbody

  if mailserver = "localhost" then
    '==This section provides the configuration information for the local SMTP server.
    Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1 
  else
    '==This section provides the configuration information for the remote SMTP server.
    Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
    'Name or IP of Remote SMTP Server
    Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailserver
    if mailauth = "NONE" then
      'Type of authentication, NONE, Basic (Base64 encoded), NTLM
      Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
	else
	  if mailauth = "BASIC" then
        'Type of authentication, NONE, Basic (Base64 encoded), NTLM
        Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
	  else
        'Type of authentication, NONE, Basic (Base64 encoded), NTLM
        Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM
	  end if
      'Your UserID on the SMTP server
      Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailuser
      'Your password on the SMTP server
      Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpassword
	end if
    'Server port (typically 25)
    Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
    'Use SSL for the connection (False or True)
    Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = mailssl
    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  end if
  Email.Configuration.Fields.Update
  
  on error resume next
  Email.Send
  
  SendCDOEmail = Err
  
  Set Email = Nothing
end function  

'-- Easy format date ---- Define variable: d, M, y
'-- Example ddd, dd-MM-yyyy = Monday, 13-03-2006
function EzFormatDate(sFormat,dDate)
  dim iLen
  dim iLoop
  dim sTmp
  dim sRet
  
  iLen = len(sFormat)
  if iLen > 0 then
    for iLoop = 1 to iLen
      sTmp = mid(sFormat, iLoop, 1)
	  'Day process
	  if sTmp = "d" then
	    sTmp = mid(sFormat, iLoop, 4)
		if sTmp = "dddd" then 
		  sTmp = WeekDayName(WeekDay(dDate))
		  iLoop = iLoop + 3
        else
	      sTmp = mid(sFormat, iLoop, 3)
		  if sTmp = "ddd" then 
		    sTmp = Left(WeekDayName(WeekDay(dDate)),3)
		    iLoop = iLoop + 2
		  else
  	        sTmp = mid(sFormat, iLoop, 2)
		    if sTmp = "dd" then
		      sTmp = LeftPad(Day(dDate),"0",2)
   		      iLoop = iLoop + 1
		    else
		      sTmp = Day(dDate)
		    end if	
		  end if
		end if  
	  end if  
	  'Month process
	  if sTmp = "M" then
	    sTmp = mid(sFormat, iLoop, 4)
		if sTmp = "MMMM" then
		  sTmp = MonthName(Month(dDate))
		  iLoop = iLoop + 3
		else
          if left(sTmp, 3) = "MMM" then
		    sTmp = Left(MonthName(Month(dDate)),3)
			iLoop = iLoop + 2
          else 
		    sTmp = Month(dDate)
		    iLoop = iLoop + 1
		  end if	
		end if
	  end if  
	  'Year process
	  if sTmp = "y" then
	    sTmp = mid(sFormat, iLoop, 4)
		if sTmp = "yyyy" then
		  sTmp = Year(dDate)
		  iLoop = iLoop + 3
		else
		  sTmp = Year(dDate)
		  if len(sTmp) = 4 then
		    sTmp = Right(sTmp,2) 
		  end if
		  iLoop = iLoop + 1
		end if
	  end if  
	  'Separator process not gain any process above
      sRet = sRet & sTmp
	next
  end if
  EzFormatDate = sRet
end function


Function dblq(s) ' double quotes
 if (s<>"") then
 dblq = replace(s,"'","''")
 end if
End Function

Function sglq(s) ' double quotes
 if (s<>"") then
 sglq = replace(s,"'"," ")
 end if
End Function
 
Function dblqjv(s) ' double quotes
 dblqjv = replace(s,"'","'+'")
 End Function
 
function delKoma(dtKoma)
  delKoma = Replace(dtKoma,",","")
end function

Function ReFormatText(e)
	ReFormatText = Replace(e, "(_quote_)", "'")
	ReFormatText = Replace(ReFormatText, "<br>", chr(10))
End Function

Function GetLoginName(e)
	  sql = "SELECT EMAIL FROM EMP WHERE EMPCODE='"& e & "'"
	  set rs = cn.execute(sql)
	  if rs.eof then
	  GetLoginName=""
	  else
	  GetLoginName = rs("EMAIL")
	  end if
	  set rs = nothing
	  'cn.close
End Function

'************** open OLEDB ******************************************
' Create connection object
set cn=Server.CreateObject("ADODB.Connection")
cn.open "PROVIDER=SQLOLEDB;DATA SOURCE=" & dbservername & ";UID=" & dbuname & ";PWD=" & dbpasswd & ";Initial Catalog=" & dbname & ";Persist Security Info=True"

      Dim UsrFullName
      Dim UsrName 
	  Dim FirstName
	  dim empCode
	  dim dept
	  dim ManagerID
	  dim isManager
	  dim theURL
	  dim emailDomain
	  dim InvoiceDoc
	  dim DOATo
	  
      UsrName = Mid(Request.ServerVariables("LOGON_USER"),16)
	  ' ===============  Kalau mau ganti user, lakukan di bawah ini  =========================
	   'UsrName="Rhonal"
	  ' ======================================================================================
	  if LCase(UsrName)="aiuzamah" then 
	  usrName="IUzamah"
	  end if  
	  
	
	  'set objGroup = GetObject("WinNT://PREMIER-GLOBAL/DOMAIN USERS" )
	  set objGroup = GetObject("WinNT://ALDIMAC/Users" )
      for Each objUser in objGroup.Members
	  if (UsrName="IUzamah") then 
	     If objUser.Class = "User" and Lcase(ObjUser.Name) = Lcase(usrname) Then
	     UsrFullName = objUser.FullName
	     End If 
	  else	  
	    If objUser.Class = "User" and LCase(ObjUser.Name) = LCase(UsrName) Then
	    UsrFullName = objUser.FullName
	    End If 
	  end if 
	  Next	 
 
	  UsrName="dgunawan"
	  UsrFullName = "DANNY GUNAWAN"
	  
	  
	  'usrName="dbudiawan"
	  'UsrFullName = "DHARMORO BUDIAWAN"
	  
	  'usrName="automo"
	  'UsrFullName = "ARI UTOMO KURNIAWAN"
	  
	  sql = "SELECT EMPCODE, FIRSTNAME, DEPARTMENT FROM EMP WHERE LOWER(EMAIL)='"& LCase(usrName) & "@premier-oil.com'"
      set rs=cn.execute(sql)
      if rs.eof then
        empCode = ""
        Dept = ""
		FirstName=""
	  else
	    empCode = rs("EMPCODE")
	    Dept = rs("DEPARTMENT")
		FirstName=rs("FIRSTNAME")
	  end if
 	  set rs=nothing
	  
	  sql = "SELECT EMPCODE, DEPARTMENT FROM EXIAUTHORITY WHERE LOWER(LOGINNAME)='"& LCase(usrName) & "'"
	  set rs=cn.execute(sql)
	  if rs.eof then
        ManagerID = ""
        isManager = "N"
	  else
	    ManagerID = rs("EMPCODE")
	    isManager = "Y"
	  end if
 	  set rs=nothing
	  
sql = "SELECT TOP 1 * FROM EXIUSERCOORD WHERE '"& LCase(UsrFullName) & "' LIKE LOWER(FULLNAME)+'%'"
	  set rs=cn.execute(sql)
	  if rs.eof then
        isUC = "N"
	  else
	    isUC = "Y"
	  end if
 	  set rs=nothing
	  sql = "SELECT URL,EMAILDOMAIN,INVOICEPATH FROM EXJRNLPREF"
	  set rs=cn.execute(sql)
	  theURL = rs("URL")
	  emailDomain = rs("EMAILDOMAIN")
	  InvoiceDoc = rs("INVOICEPATH")
	  set rs=nothing	  
	  
'--------------------------------is Delegete to this  user?
sql = "SELECT EMPCODE, DEPARTMENT FROM EXIAUTHORITY WHERE ISDOA='Y' AND DOATO='"& empCode & "'"
set rs=cn.execute(sql)
if rs.eof then
  mgrCode =""
  bDOA="N"
else
  mgrCode=rs("EMPCODE")
  bDOA="Y" 
end if
set rs=nothing
'----------------------------------------------------------

%>
